-
Notifications
You must be signed in to change notification settings - Fork 14
Add response_format parameter support for structured output #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements response_format parameter to enable JSON mode and JSON schema output formatting for both Meta Llama and Cohere models. This allows users to leverage structured output capabilities via with_structured_output() and direct response_format configuration. Changes: - Add response_format field to OCIGenAIBase with comprehensive documentation - Implement response_format handling in ChatOCIGenAI._prepare_request method - Support response_format via class initialization, bind(), and model_kwargs - Add comprehensive unit tests covering all configuration methods - Add integration tests validating end-to-end functionality with real API calls The implementation ensures response_format is properly passed to both GenericChatRequest (Meta Llama) and CohereChatRequest (Cohere) models. Fixes oracle#33
|
Hi @YouNeedCryDear! 👋 I hope you're doing well! I wanted to gently follow up on this PR that adds Why this matters: What's been validated:
This follows the same parameter pattern as other recent enhancements and should be a straightforward addition to the SDK's capabilities. Would you have a chance to take a look when you get a moment? I'm happy to address any feedback or questions you might have! Thanks so much for maintaining this project! 🙏 |
|
@fede-kamel Why do we need |
Response to Review Feedback@YouNeedCryDear Changes Made
Why This ApproachThis makes the OCI implementation consistent with other LangChain providers (OpenAI, Anthropic, etc.) where response format parameters are handled through Real-World TestingTo verify the functionality still works correctly after these changes, I tested with real OCI Generative AI API calls: With Meta Llama 4 model: llm = ChatOCIGenAI(
model_id="meta.llama-4-maverick-17b-128e-instruct-fp8",
model_kwargs={"response_format": {"type": "JSON_OBJECT"}},
# ... other config
)
response = llm.invoke("Create JSON with name and age for Alice who is 30")
# Returns: {"name": "Alice", "age": 30}Tested successfully with:
The response format functionality works perfectly and enforces proper JSON output from the models. This change maintains backward compatibility while providing a cleaner, more consistent API design. Users can still access all the structured output features through |
|
Hi @YouNeedCryDear, just following up—this PR is ready for another look whenever you have a moment. Appreciate your previous feedback! |
|
@fede-kamel Sorry I don't see any new changes after our discussion. |
Summary
Implements response_format parameter to enable JSON mode and JSON schema output formatting for both Meta Llama and Cohere models. This allows users to leverage structured output capabilities via
with_structured_output()and direct response_format configuration.Changes
Implementation Details
The implementation ensures response_format is properly passed to both GenericChatRequest (Meta Llama) and CohereChatRequest (Cohere) models by adding the parameter to the model_kwargs in the _prepare_request method.
Testing
Unit Tests: 9/9 tests passing
Integration Tests: 10/10 tests passing with real OCI API calls
Fixes
Fixes #33
Breaking Changes
None - this is a new feature that is fully backward compatible.